﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="分厂进度日报表.aspx.cs" Inherits="syc.Fc.分厂进度日报表" %>
<html>
<head>
<style>
#op{display:none;}
</style>
</head>
<body>
<script type="text/javascript" language="javascript" src="/common.js"></script>
<form id="form1" runat="server">
<div id="wintop" class="wintop">分厂进度日报表</div>
<asp:Panel ID="Panel1" runat="server" CssClass="panel">
    分厂：<asp:DropDownList ID="FenChang" runat="server" Width="80px" AutoPostBack="true" >
        <asp:ListItem Value="1">一分厂</asp:ListItem>
        <asp:ListItem Value="2">二分厂</asp:ListItem>
        <asp:ListItem Value="5">五分厂</asp:ListItem>
        </asp:DropDownList>
    日期：<asp:TextBox ID="Date1" runat="server" CssClass="textbox" Width="110px"  AutoPostBack="true"></asp:TextBox>
        <img alt="" src="/Icons/29.png" align="middle" onclick="makecalendar(document.getElementById('Date1').value, document.getElementById('Date1'));" />
    累计日期：<asp:TextBox ID="Date2" runat="server" CssClass="textbox" Width="110px" Enabled="false" BackColor="#eeeeee"></asp:TextBox>
    年累计日期：<asp:TextBox ID="Date3" runat="server" CssClass="textbox" Width="110px" Enabled="false" BackColor="#eeeeee"></asp:TextBox>
        
    <input type="button" value="导出Excel" class="button" onclick="Export();" style="font-weight:normal" />

</asp:Panel>

<asp:Panel ID="Panel2" runat="server" CssClass="panel3">
<style>
tr{height:33px;}
td{border:.5pt solid #000000;text-align:center;font-size:12pt;font-family:宋体;}
td.nb{border:none;}

td.s1{border-top:1pt solid #000000;border-left:1pt solid #000000;}
td.s2{border-top:1pt solid #000000;}
td.s3{border-top:1pt solid #000000;border-right:1pt solid #000000;}
td.s4{border-left:1pt solid #000000;}
td.s5{border-right:1pt solid #000000;}
td.s6{border-left:1pt solid #000000;border-bottom:1pt solid #000000;}
td.s7{border-bottom:1pt solid #000000;}
td.s8{border-right:1pt solid #000000;border-bottom:1pt solid #000000;}
br{mso-data-placement:same-cell;}
</style>
<table border="0" cellpadding="0" style="border-collapse:collapse;">
<tr>
<td class="nb" colspan="11" style="height:45px;font-size:20pt;font-weight:bold;">生 产 进 度 日 报 表</td>
</tr>
<tr style="height:28px">
<td class="nb" colspan="5" style="text-align:left;font-weight:bold;">&nbsp; 填报单位：<%=this.FenChang.SelectedItem.Text %></td>
<td class="nb" colspan="4"></td>
<td class="nb" colspan="2" style="text-align:right;font-weight:bold;">日 期：<%=this.Date1.Text %>&nbsp; </td>
</tr>
<tr>
<td class="s1" colspan="3">车丝机</td>
<td class="s2" colspan="2"><b>1#</b></td>
<td class="s2" width="125"><b>2#</b></td>
<td class="s2" width="125"><b>3#</b></td>
<td class="s2" colspan="2"><b>4#</b></td>
<td class="s2" width="125"><b>5#</b></td>
<td class="s3" width="125"><b>6#</b></td>
</tr>


<%
    DateTime d1, d2, d3;
    if (DateTime.TryParse(Date1.Text, out d1))
    {
        System.Data.SqlClient.SqlConnection Conn = new System.Data.SqlClient.SqlConnection();
        Conn.ConnectionString = ConfigurationManager.ConnectionStrings["SCMConnectionString1"].ConnectionString;
        Conn.Open();
        System.Data.SqlClient.SqlCommand Cmd = new System.Data.SqlClient.SqlCommand();
        Cmd.Connection = Conn;

        Cmd.CommandText =
@"declare @y int
declare @d1 date
if exists(select * from 生产月设置 where 分厂=@fc and @d0>=起始日期 and @d0<=截止日期)
begin
	select @y=年度,@d1=起始日期 from 生产月设置 where 分厂=@fc and @d0>=起始日期 and @d0<=截止日期
	if exists(select * from 生产月设置 where 分厂=@fc and 年度=@y and 月份=1)
	begin
		select @d1 as 月累计日期,起始日期 as 年累计日期 from 生产月设置 where 分厂=@fc and 年度=@y and 月份=1
	end
end";
        Cmd.CommandText = Cmd.CommandText.Replace("@d0", "'" + d1.ToShortDateString() + "'");
        Cmd.CommandText = Cmd.CommandText.Replace("@fc", this.FenChang.Text);
        Cmd.CommandType = System.Data.CommandType.Text;
        System.Data.SqlClient.SqlDataReader Reader = Cmd.ExecuteReader();
        if (Reader.Read())
        {
            d2 = (DateTime)Reader["月累计日期"];
            d3 = (DateTime)Reader["年累计日期"];
            this.Date2.Text = d2.ToLongDateString();
            this.Date3.Text = d3.ToLongDateString();
        }
        else
        {
            this.Date2.Text = d1.Year.ToString() + "年" + d1.Month.ToString() + "月1日";
            this.Date3.Text = d1.Year.ToString() + "年1月1日";
            d2 = DateTime.Parse(this.Date2.Text);
            d3 = DateTime.Parse(this.Date3.Text);
        }
        Reader.Close();


        //车丝
        Cmd.CommandText = "select * from (select sum(车丝1) as c1,sum(车丝2) as c2,sum(车丝3) as c3,sum(车丝4) as c4,sum(车丝5) as c5,sum(车丝6) as c6 from 生产进度 where 日期='"
            + d1.ToShortDateString() + "' and 分厂ID=" + FenChang.Text + ") t1,"
            + "(Select sum(车丝1) as c7,sum(车丝2) as c8,sum(车丝3) as c9,sum(车丝4) as c10,sum(车丝5) as c11,sum(车丝6) as c12 from 生产进度 where 日期>='"
            + d2.ToShortDateString() + "' and 日期<='" + d1.ToShortDateString() + "' and 分厂ID=" + FenChang.Text + ") t2"
            + "";
        Cmd.CommandType = System.Data.CommandType.Text;
        Reader = Cmd.ExecuteReader();

        string[] data = new string[18];
        if (Reader.Read())
        {
            for (int i = 0; i < 12; i++)
            {
                if (!Reader.IsDBNull(i))
                {
                    if (Reader.GetInt32(i) != 0)
                    {
                        data[i] = Reader.GetInt32(i).ToString();
                    }
                }
            }
        }
        Response.Write("<tr><td class=s4 colspan=3>当日车丝(支)</td><td colspan=2>" 
            + data[0] + "</td><td>"
            + data[1] + "</td><td>"
            + data[2] + "</td><td colspan=2>"
            + data[3] + "</td><td>"
            + data[4] + "</td><td class=s5>"
            + data[5] + "</td></tr>");
        Response.Write("<tr><td class=s4 colspan=3>本月累计(支)</td><td colspan=2>"
            + data[6] + "</td><td>"
            + data[7] + "</td><td>"
            + data[8] + "</td><td colspan=2>"
            + data[9] + "</td><td>"
            + data[10] + "</td><td class=s5>"
            + data[11] + "</td></tr>");
        Reader.Close();

        Response.Write("<tr><td class=s1 colspan=3>名 称</td><td class=s2 width=38>单位</td><td class=s2 width=90>当 日</td><td class=s2>本月累计</td><td class=s2>本年累计</td>"
            + "<td class=s2 width=38>单位</td><td class=s2 width=90>当 日</td><td class=s2>本月累计</td><td class=s3>本年累计</td></tr>");


        Cmd.CommandText =
@"declare @fc int, @d1 date,@d2 date,@d3 date;
set @fc="+this.FenChang.Text+@";
set @d1='"+d1.ToShortDateString()+@"';
set @d2='" + d2.ToShortDateString() + @"';
set @d3='" + d3.ToShortDateString() + @"';
select 产品类别ID
,SUM(case when 日期=@d1 then 称测支数 else 0 end),SUM(case when 日期>=@d2 then 称测支数 else 0 end),SUM(称测支数)
,SUM(case when 日期=@d1 then 称测重量 else 0 end),SUM(case when 日期>=@d2 then 称测重量 else 0 end),SUM(称测重量)
,SUM(case when 日期=@d1 then 包装捆数 else 0 end),SUM(case when 日期>=@d2 then 包装捆数 else 0 end),SUM(包装捆数)
,SUM(case when 日期=@d1 then 包装重量 else 0 end),SUM(case when 日期>=@d2 then 包装重量 else 0 end),SUM(包装重量)
,SUM(case when 日期=@d1 then 入库捆数 else 0 end),SUM(case when 日期>=@d2 then 入库捆数 else 0 end),SUM(入库捆数)
,SUM(case when 日期=@d1 then 入库重量 else 0 end),SUM(case when 日期>=@d2 then 入库重量 else 0 end),SUM(入库重量)
from 生产进度 where 日期 between @d3 and @d1 and 分厂ID=@fc group by 产品类别ID order by 产品类别ID";
        
        Cmd.CommandType = System.Data.CommandType.Text;
        Reader = Cmd.ExecuteReader();
        string cp="", gj="";
        if (Reader.Read())
        {
            do
            {
                for (int i = 1; i <= 18; i++)
                {
                    data[i - 1] = Reader[i].ToString();
                }
                if (Reader.GetInt32(0) == 1)
                {
                    cp = "油<br><br>管";
                    gj = "J55";
                }
                else if (Reader.GetInt32(0) == 2)
                {
                    cp = "套<br><br>管";
                    gj = "J55";
                }
                else if (Reader.GetInt32(0) == 3)
                {
                    cp = "油<br><br>管";
                    gj = "N80Q";
                }
                else if (Reader.GetInt32(0) == 4)
                {
                    cp = "套<br><br>管";
                    gj = "N80Q";
                }
                Response.Write("<tr><td class=s6 rowspan=3 width=36>" + cp + "</td><td class=s7 rowspan=3 width=36>" + gj
                    + "</td><td width=85>称重测长</td><td>支</td><td width=90>" + data[0] + "</td><td>" + data[1] + "</td><td>" + data[2]
                    + "</td><td>kg</td><td width=90>" + data[3] + "</td><td>" + data[4] + "</td><td class=s5>" + data[5] + "</td></tr>"
                    + "<tr><td>成品精整</td><td>捆</td><td>" + data[6] + "</td><td>" + data[7] + "</td><td>" + data[8]
                    + "</td><td>kg</td><td>" + data[9] + "</td><td>" + data[10] + "</td><td class=s5>" + data[11] + "</td></tr>"
                    + "<tr><td class=s7>成品入库</td><td class=s7>捆</td><td class=s7>" + data[12] + "</td><td class=s7>" + data[13] + "</td><td class=s7>" + data[14]
                    + "</td><td class=s7>kg</td><td class=s7>" + data[15] + "</td><td class=s7>" + data[16] + "</td><td class=s8>" + data[17] + "</td></tr>");
            }
            while (Reader.Read());
        }
        else
        {
            Response.Write(@"<tr><td class=s6 rowspan=3 width=36></td><td class=s7 rowspan=3 width=36></td><td width=85>称重测长</td>
<td>支</td><td width=90></td><td></td><td></td>
<td>kg</td><td width=90></td><td></td><td class=s5></td></tr>
<tr><td>成品精整</td><td>捆</td><td></td><td></td><td></td>
<td>kg</td><td></td><td></td><td class=s5></td></tr>
<tr><td class=s7>成品入库</td><td class=s7>捆</td><td class=s7></td><td class=s7></td><td class=s7></td>
<td class=s7>kg</td><td class=s7></td><td class=s7></td><td class=s8></td></tr>");
        }
        
        Conn.Close();
        Reader.Dispose();
        Cmd.Dispose();
        Conn.Dispose();
    }
    else
    {
        this.Notice = "日期录入有误";
    }
  
%>



<tr style="height:26px">
<td class="nb" colspan="3" style="text-align:right;">负责人：</td>
<td class="nb" colspan="2" style="text-align:left;"></td>
<td class="nb"></td>
<td class="nb"></td>
<td class="nb" colspan="2"></td>
<td class="nb" style="text-align:right;">填报人：</td>
<td class="nb" style="text-align:left;"><span style="display:none;"><%=(string)this.Session["OperatorName"]%></span></td>
</tr>
</table>
</asp:Panel>

</form>

<form id="form2" method="post" action="/PageExport.ashx">
<input type="hidden" name="filename" value="生产进度日报表.xls" />
<input type="hidden" name="content" value="" />
</form>
<script type="text/javascript">
    var notice = '<%=this.Notice %>';
    if (notice != '') {
        parent.showmsgbox(notice);
    }
    document.getElementById("Date2").value = "<%=this.Date2.Text %>";
    document.getElementById("Date3").value = "<%=this.Date3.Text %>";
</script>
<script type="text/javascript">
var textboxs = document.getElementsByTagName("input");
for (var i = 0; i < textboxs.length; i++) {
    if (textboxs[i].className == "pageturn" || textboxs[i].className == "intxt1" || textboxs[i].className == "intxt2") {
        textboxs[i].onfocus = function(e) { this.select(); };
    }
}
function Export() {
    form2.content.value =
"<html xmlns:o='urn:schemas-microsoft-com:office:office'\nxmlns:x='urn:schemas-microsoft-com:office:excel'\nxmlns='http://www.w3.org/TR/REC-html40'>\n<head>\n<meta http-equiv=Content-Type content='text/html; charset=utf-8'>\n<style>\n<!--table\n@page\n{mso-header-data:;\nmso-footer-data:;\nmargin:.79in .31in .79in .31in;\nmso-header-margin:.51in;\nmso-footer-margin:.51in;\nmso-page-orientation:landscape;\nmso-horizontal-page-align:center;\n}\n-->\n</style>\n<!--[if gte mso 9]><xml>\n<x:ExcelWorkbook>\n<x:ExcelWorksheets>\n<x:ExcelWorksheet>\n<x:Name>生产进度日报表</x:Name>\n<x:WorksheetOptions>\n<x:DefaultRowHeight>285</x:DefaultRowHeight>\n<x:Print>\n<x:ValidPrinterInfo/>\n<x:Scale>100</x:Scale>\n<x:PaperSizeIndex>9</x:PaperSizeIndex>\n<x:HorizontalResolution>200</x:HorizontalResolution>\n<x:VerticalResolution>200</x:VerticalResolution>\n</x:Print>\n<x:Selected/>\n<x:Panes>\n<x:Pane>\n<x:Number>3</x:Number>\n<x:ActiveRow>0</x:ActiveRow>\n<x:ActiveCol>0</x:ActiveCol>\n</x:Pane>\n</x:Panes>\n</x:WorksheetOptions>\n</x:ExcelWorksheet>\n</x:ExcelWorkbook>\n</xml><![endif]-->\n</head>\n<body>"
            + document.getElementById("Panel2").innerHTML
            + "</body></html>";
    form2.submit();
}

parent.hidesubmenu(true);
</script>
</body>
</html>